package com.learning.platform.dto;

import com.learning.platform.entity.Course;
import com.learning.platform.enums.CourseStatus;
import com.learning.platform.enums.Difficulty;

import java.math.BigDecimal;
import java.time.LocalDateTime;

public class CourseResponse {
    private Long id;
    private String title;
    private String description;
    private String coverUrl;
    private Long categoryId;
    private BigDecimal price;
    private Integer enrollmentCount;
    private BigDecimal averageRating;
    private Integer reviewCount;
    private Difficulty difficulty;
    private Long teacherId;
    private CourseStatus status;
    private LocalDateTime createdAt;
    private LocalDateTime updatedAt;
    private Integer lessonCount;
    
    // 无参构造函数
    public CourseResponse() {}
    
    public CourseResponse(Course course) {
        this.id = course.getId();
        this.title = course.getTitle();
        this.description = course.getDescription();
        this.coverUrl = course.getCoverUrl();
        this.categoryId = course.getCategoryId();
        this.price = course.getPrice() != null ? course.getPrice() : BigDecimal.ZERO;
        this.enrollmentCount = course.getEnrollmentCount() != null ? course.getEnrollmentCount() : 0;
        this.averageRating = course.getAverageRating() != null ? course.getAverageRating() : BigDecimal.ZERO;
        this.reviewCount = course.getReviewCount() != null ? course.getReviewCount() : 0;
        this.difficulty = course.getDifficulty() != null ? course.getDifficulty() : Difficulty.BEGINNER;
        this.teacherId = course.getTeacherId();
        this.status = course.getStatus() != null ? course.getStatus() : CourseStatus.DRAFT;
        this.createdAt = course.getCreatedAt();
        this.updatedAt = course.getUpdatedAt();
        // 注意：不要访问懒加载的lessons集合，这会导致LazyInitializationException
        this.lessonCount = 0; // 将在service层单独设置
    }
    
    // Getters and Setters
    public Long getId() { return id; }
    public void setId(Long id) { this.id = id; }
    
    public String getTitle() { return title; }
    public void setTitle(String title) { this.title = title; }
    
    public String getDescription() { return description; }
    public void setDescription(String description) { this.description = description; }
    
    public String getCoverUrl() { return coverUrl; }
    public void setCoverUrl(String coverUrl) { this.coverUrl = coverUrl; }
    
    public Long getCategoryId() { return categoryId; }
    public void setCategoryId(Long categoryId) { this.categoryId = categoryId; }
    
    public BigDecimal getPrice() { return price; }
    public void setPrice(BigDecimal price) { this.price = price; }
    
    public Integer getEnrollmentCount() { return enrollmentCount; }
    public void setEnrollmentCount(Integer enrollmentCount) { this.enrollmentCount = enrollmentCount; }
    
    public BigDecimal getAverageRating() { return averageRating; }
    public void setAverageRating(BigDecimal averageRating) { this.averageRating = averageRating; }
    
    public Integer getReviewCount() { return reviewCount; }
    public void setReviewCount(Integer reviewCount) { this.reviewCount = reviewCount; }
    
    public Difficulty getDifficulty() { return difficulty; }
    public void setDifficulty(Difficulty difficulty) { this.difficulty = difficulty; }
    
    public Long getTeacherId() { return teacherId; }
    public void setTeacherId(Long teacherId) { this.teacherId = teacherId; }
    
    public CourseStatus getStatus() { return status; }
    public void setStatus(CourseStatus status) { this.status = status; }
    
    public LocalDateTime getCreatedAt() { return createdAt; }
    public void setCreatedAt(LocalDateTime createdAt) { this.createdAt = createdAt; }
    
    public LocalDateTime getUpdatedAt() { return updatedAt; }
    public void setUpdatedAt(LocalDateTime updatedAt) { this.updatedAt = updatedAt; }
    
    public Integer getLessonCount() { return lessonCount; }
    public void setLessonCount(Integer lessonCount) { this.lessonCount = lessonCount; }
}

